package ui;

import java.awt.MenuBar;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;

import templates.JOGLTemplate;

public class JOGLQuad extends JOGLTemplate {

	float rotateT = 0.0f;

	public JOGLQuad() {
		super();
		canvas.addGLEventListener(new JOGLQuad());
		start("JOGLSquad");
	}

	@Override
	public void init(GLAutoDrawable gLDrawable) {
		super.init(gLDrawable);
		GL2 gl = gLDrawable.getGL().getGL2();
		gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glClearDepth(1.0f);
		gl.glEnable(GL.GL_DEPTH_TEST);
		gl.glDepthFunc(GL.GL_LEQUAL);
		gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
	}

	@Override
	public void display(GLAutoDrawable gLDrawable) {
		final GL2 gl = gLDrawable.getGL().getGL2();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();
		gl.glTranslatef(0.0f, 0.0f, -5.0f);

		// rotate on the three axis
		gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
		gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
		gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

		// Draw A Quad
		gl.glBegin(GL2.GL_QUADS);
		gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
		gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
		gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
		gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
		gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
		// Done Drawing The Quad
		gl.glEnd();

		// increasing rotation for the next iteration
		rotateT += 0.2f;
	}

	@Override
	public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width,
			int height) {
		GL2 gl = gLDrawable.getGL().getGL2();
		if (height <= 0) {
			height = 1;
		}
		float h = (float) width / (float) height;
		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
		gl.glLoadIdentity();
		glu.gluPerspective(50.0f, h, 1.0, 1000.0);
		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
		gl.glLoadIdentity();
	}

	public static void main(String[] args) {
		new JOGLQuad();
	}

	@Override
	public void dispose(GLAutoDrawable arg0) {
	}

	@Override
	public void rotate(double x, double y) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyboardGestion(int keyCode) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resetCamera() {
		// TODO Auto-generated method stub

	}

	@Override
	public void enableLights() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public MenuBar createMenuBar() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void animate() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void createLights() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void draw() {
		// TODO Auto-generated method stub
		
	}
}